package com.zxl.study.confusion.v4;

import com.zxl.study.confusion.OrderDetailModel;
import com.zxl.study.confusion.OrderMainModel;

import java.util.List;

/**职责链模式的 Client，在这里构建职责链
 * @auther zxl
 * @create 2023-08-13 15:24
 */
public class NormalOrderServiceImpl  implements OrderStrategy
{
    public Long saveSaleOrder(OrderMainModel orderMainModel,List<OrderDetailModel> orderDetailModelList)
    {
        //创建并组装职责链

        //1：创建：创建职责对象的实例
        SaveOrderDataHandler saveOrderDataHandler =                 new SaveOrderDataHandler();
        JudgeOrderNeedAuditHandler judgeOrderNeedAuditHandler =     new JudgeOrderNeedAuditHandler();
        NeedCustomrAuditHandler needCustomrAuditHandler =           new NeedCustomrAuditHandler();
        NotNeedCustomerAuditHandler notNeedCustomerAuditHandler =   new NotNeedCustomerAuditHandler();
        JudgeSettlementTypeHandler judgeSettlementTypeHandler =     new JudgeSettlementTypeHandler();
        AutoPayHandler autoPayHandler =                             new AutoPayHandler();
        SplitOrderHandler splitOrderHandler =                       new SplitOrderHandler();
        SendEventHandler sendEventHandler =                         new SendEventHandler();
        CashPayHandler cashPayHandler =                             new CashPayHandler();

        //2：组装：组装职责链
        saveOrderDataHandler.setSuccessor(judgeOrderNeedAuditHandler);
        judgeOrderNeedAuditHandler.setSuccessor(needCustomrAuditHandler);
        needCustomrAuditHandler.setSuccessor(notNeedCustomerAuditHandler);
        notNeedCustomerAuditHandler.setSuccessor(judgeSettlementTypeHandler);
        judgeSettlementTypeHandler.setSuccessor(autoPayHandler);
        autoPayHandler.setSuccessor(splitOrderHandler);
        splitOrderHandler.setSuccessor(sendEventHandler);
        sendEventHandler.setSuccessor(cashPayHandler);


        //3：调用:调用职责链
        SaveOrderRequestModel saveOrderRequestModel = new SaveOrderRequestModel();
        saveOrderRequestModel.setOrderMainModel(orderMainModel);
        saveOrderRequestModel.setOrderDetailModelList(orderDetailModelList);

        saveOrderDataHandler.handleRequest(saveOrderRequestModel);

        return saveOrderRequestModel.getResultOrderMainUuid();
    }
}
